package com.huilian.iotbox.data.utils;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.WeekFields;
import java.util.Date;

/**
 * java1.8 新增时间类型（DateTimeFormatter线程安全）
 *
 * @author lizhiquan
 * @date 2020/6/6 20:47
 */
public class DateTimeUtils {

    public static void main(String[] args) {
        System.out.println(DateTimeUtils.getYearFirstDayTimeYM());
        System.out.println(DateTimeUtils.getMonthYM());
    }


    public static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HHmmss");
    public static final DateTimeFormatter YEAR_MONTH_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM");
    public static final DateTimeFormatter SHORT_DATE_FORMATTER = DateTimeFormatter.ofPattern("yyMMdd");
    public static final DateTimeFormatter LONG_DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
    public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    public static final DateTimeFormatter SHORT_DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyMMddHHmmss");
    public static final DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    public static final DateTimeFormatter LONG_DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss SSS");

    public static final DateTimeFormatter START_DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd 00:00:00");
    public static final DateTimeFormatter END_DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd 23:59:59");

    /**
     * @param date    传递过来的时间
     * @param pattern 需要格式化类型
     */
    public static String convert(LocalDate date, DateTimeFormatter pattern) {
        return date.format(pattern);
    }

    /**
     * 获取当前时间
     */
    public static String currTime() {
        return LocalDateTime.now().format(DATETIME_FORMATTER);
    }

    public static String getCurrTime() {
        return LocalDateTime.now().format(DATE_FORMATTER);
    }

    /**
     * 获取昨天日期
     */
    public static String getYesterday() {
        return LocalDate.now().minusDays(1).format(DATE_FORMATTER);
    }

    /**
     * 获取昨天开始时间
     */
    public static String getYesterdayStartTime() {
        return LocalDate.now().minusDays(1).format(START_DATETIME_FORMATTER);
    }

    /**
     * 几分钟之前
     *
     * @param minutes
     * @return
     */
    public static String getSomeMinutesAgo(int minutes) {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime time = date.minus(minutes, ChronoUnit.MINUTES);
        return time.format(DATETIME_FORMATTER);
    }

    /**
     * 几天之前
     *
     * @param days
     * @return
     */
    public static String getSomeDaysAgo(int days) {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime time = date.minus(days, ChronoUnit.DAYS);
        return time.format(DATETIME_FORMATTER);
    }

    /**
     * 获取昨天结束时间
     */
    public static String getYesterdayEndTime() {
        return LocalDate.now().minusDays(1).format(END_DATETIME_FORMATTER);
    }

    /**
     * 获取今天开始时间
     */
    public static String getTodayStartTime() {
        return LocalDate.now().format(START_DATETIME_FORMATTER);
    }

    /**
     * 获取今天结束时间
     */
    public static String getTodayEndTime() {
        return LocalDate.now().format(END_DATETIME_FORMATTER);
    }

    /**
     * 获取本月第一天开始时间
     */
    public static String getMonthFirstDayTime() {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime firstDay = date.with(TemporalAdjusters.firstDayOfMonth());
        return firstDay.format(START_DATETIME_FORMATTER);
    }

    /**
     * 获取本月最后一天结束时间
     */
    public static String getMonthLastDayTime() {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime lastDay = date.with(TemporalAdjusters.lastDayOfMonth());
        return lastDay.format(END_DATETIME_FORMATTER);
    }

    /**
     * 获取本年第一天开始时间
     */
    public static String getYearFirstDayTime() {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime firstDay = date.with(TemporalAdjusters.firstDayOfYear());
        return firstDay.format(START_DATETIME_FORMATTER);
    }

    /**
     * 获取本年第一天开始时间YM格式
     */
    public static String getYearFirstDayTimeYM() {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime firstDay = date.with(TemporalAdjusters.firstDayOfYear());
        return firstDay.format(YEAR_MONTH_FORMATTER);
    }

    /**
     * 获取本年第一天开始时间YMD
     */
    public static String getYearFirstDayTimeYMD() {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime firstDay = date.with(TemporalAdjusters.firstDayOfYear());
        return firstDay.format(DATE_FORMATTER);
    }

    /**
     * 获取本年最后一天结束时间
     */
    public static String getYearLastDayTime() {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime lastDay = date.with(TemporalAdjusters.lastDayOfYear());
        return lastDay.format(END_DATETIME_FORMATTER);
    }


    /**
     * 获取本年第一天
     */
    public static String getYearFirstDay() {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime firstDay = date.with(TemporalAdjusters.firstDayOfYear());
        return firstDay.format(DATE_FORMATTER);
    }

    /**
     * 获取本年最后一天
     */
    public static String getYearLastDay() {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime lastDay = date.with(TemporalAdjusters.lastDayOfYear());
        return lastDay.format(DATE_FORMATTER);
    }

    /**
     * 获取本月
     */
    public static String getMonthDay() {
        LocalDate date = LocalDate.now();
        return date.format(DATE_FORMATTER);
    }

    public static String getMonthYM() {
        LocalDate date = LocalDate.now();
        return date.format(YEAR_MONTH_FORMATTER);
    }

    /**
     * 获取本月第一天
     */
    public static String getMonthFirstDay() {
        LocalDate date = LocalDate.now();
        LocalDate firstDay = date.with(TemporalAdjusters.firstDayOfMonth());
        return firstDay.format(DATE_FORMATTER);
    }

    /**
     * 获取本月最后一天
     */
    public static String getMonthLastDay() {
        LocalDate date = LocalDate.now();
        LocalDate lastDay = date.with(TemporalAdjusters.lastDayOfMonth());
        return lastDay.format(DATE_FORMATTER);
    }

    /**
     * 获取本周第一天
     */
    public static String getWeekFirstDay() {
        LocalDate now = LocalDate.now();
        WeekFields weekFields = WeekFields.ISO;
        LocalDate mondayDate = now.with(weekFields.dayOfWeek(), 1L);
        return mondayDate.format(DATE_FORMATTER);
    }

    /**
     * 获取本周最后一天
     */
    public static String getWeekLastDay() {
        LocalDate now = LocalDate.now();
        WeekFields weekFields = WeekFields.ISO;
        LocalDate sundayDate = now.with(weekFields.dayOfWeek(), 7L);
        return sundayDate.format(DATE_FORMATTER);
    }

    /**
     * 获取上月
     */
    public static String getPreviousMonthYM() {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime firstDay = date.minus(1, ChronoUnit.MONTHS).with(TemporalAdjusters.firstDayOfMonth());
        return firstDay.format(YEAR_MONTH_FORMATTER);
    }

    /**
     * 获取上月第一天
     */
    public static String getPreviousMonthFirstDay() {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime firstDay = date.minus(1, ChronoUnit.MONTHS).with(TemporalAdjusters.firstDayOfMonth());
        return firstDay.format(DATE_FORMATTER);
    }

    /**
     * 获取上月最后一天
     */
    public static String getPreviousMonthLastDay() {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime lastDay = date.minus(1, ChronoUnit.MONTHS).with(TemporalAdjusters.lastDayOfMonth());
        return lastDay.format(DATE_FORMATTER);
    }

    /**
     * 获取上月第一天开始时间
     */
    public static String getPreviousMonthFirstDayTime() {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime firstDay = date.minus(1, ChronoUnit.MONTHS).with(TemporalAdjusters.firstDayOfMonth());
        return firstDay.format(START_DATETIME_FORMATTER);
    }

    /**
     * 获取上月最后一天结束时间
     */
    public static String getPreviousMonthLastDayTime() {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime lastDay = date.minus(1, ChronoUnit.MONTHS).with(TemporalAdjusters.lastDayOfMonth());
        return lastDay.format(END_DATETIME_FORMATTER);
    }


    /**
     * 获取某月第一天开始时间
     */
    public static String getSomeMonthFirstDayTime(String time) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDateTime localDateTime = LocalDateTime.of(LocalDate.parse(time, formatter), LocalTime.MIN).with(TemporalAdjusters.firstDayOfMonth());
        return localDateTime.format(START_DATETIME_FORMATTER);
    }

    /**
     * 获取某月最后一天结束时间
     */
    public static String getSomeMonthLastDayTime(String time) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDateTime localDateTime = LocalDateTime.of(LocalDate.parse(time, formatter), LocalTime.MIN).with(TemporalAdjusters.lastDayOfMonth());
        return localDateTime.format(END_DATETIME_FORMATTER);
    }

    /**
     * 获取某月第一天
     */
    public static String getSomeMonthFirstDay(String time) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDateTime localDateTime = LocalDateTime.of(LocalDate.parse(time, formatter), LocalTime.MIN).with(TemporalAdjusters.firstDayOfMonth());
        return localDateTime.format(DATE_FORMATTER);
    }

    /**
     * 获取某月最后一天
     */
    public static String getSomeMonthLastDay(String time) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDateTime localDateTime = LocalDateTime.of(LocalDate.parse(time, formatter), LocalTime.MIN).with(TemporalAdjusters.lastDayOfMonth());
        return localDateTime.format(DATE_FORMATTER);
    }

    public static Date plusDaysDate(int day) {
        LocalDateTime localDateTime = LocalDateTime.now().plusDays(day);
        return localDateTimeChangeDate(localDateTime);
    }

    public static Date plusWeeksDate(int week) {
        LocalDateTime localDateTime = LocalDateTime.now().plusWeeks(week);
        return localDateTimeChangeDate(localDateTime);
    }

    public static Date plusMonthsDate(int month) {
        LocalDateTime localDateTime = LocalDateTime.now().plusMonths(month);
        return localDateTimeChangeDate(localDateTime);
    }

    public static Date plusMonthsDate(Date date, int month) {
        LocalDateTime localDateTime = dateChangeLocalDateTime(date).plusMonths(month);
        return localDateTimeChangeDate(localDateTime);
    }

    public static Date plusYearsDate(int years) {
        LocalDateTime localDateTime = LocalDateTime.now().plusYears(years);
        return localDateTimeChangeDate(localDateTime);
    }

    public static Date plusYearsDate(Date date, int years) {
        LocalDateTime localDateTime = dateChangeLocalDateTime(date).plusYears(years);
        return localDateTimeChangeDate(localDateTime);
    }

    public static LocalDateTime plusDays(int day) {
        return LocalDateTime.now().plusDays(day);
    }

    public static LocalDateTime plusWeeks(int week) {
        return LocalDateTime.now().plusWeeks(week);
    }

    public static LocalDateTime plusMonths(int month) {
        return LocalDateTime.now().plusMonths(month);
    }

    public static LocalDateTime plusYears(int years) {
        return LocalDateTime.now().plusYears(years);
    }


    /**
     * 获取多少个月之后的今天
     */
    public static String getSomeMonthToday(int num) {
        return LocalDate.now().plusMonths(num).format(START_DATETIME_FORMATTER);
    }

    /**
     * 获取多少个月之前的今天
     */
    public static String getMinusMonthToday(int num) {
        return LocalDate.now().minusMonths(num).format(START_DATETIME_FORMATTER);
    }

    /**
     * 获取上个月份
     */
    public static String getPreviousMonth() {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime firstDay = date.minusMonths(1);
        return firstDay.format(YEAR_MONTH_FORMATTER);
    }

    /**
     * 获取几天前的开始时间
     *
     * @param day
     * @return
     */
    public static String getSomeDayBeforeStartTime(int day) {
        return LocalDate.now().minusDays(day).format(START_DATETIME_FORMATTER);
    }

    /**
     * 获取几天前的结束时间
     *
     * @param day
     * @return
     */
    public static String getSomeDayBeforeEndTime(int day) {
        return LocalDate.now().minusDays(day).format(END_DATETIME_FORMATTER);
    }

    /**
     * 获取几天后的开始时间
     *
     * @param day
     * @return
     */
    public static String getSomeDayLaterStartTime(int day) {
        return LocalDate.now().plusDays(day).format(START_DATETIME_FORMATTER);
    }

    /**
     * 获取几天后的结束时间
     *
     * @param day
     * @return
     */
    public static String getSomeDayLaterEndTime(int day) {
        return LocalDate.now().plusDays(day).format(END_DATETIME_FORMATTER);
    }


    /**
     * 获取某月前的结束时间
     *
     * @param months
     * @return
     */
    public static String getSomeMonthBeforeEndTime(int months) {
        return LocalDate.now().minusMonths(months).format(END_DATETIME_FORMATTER);
    }

    /**
     * 获取某月前的日期
     *
     * @param months
     * @return
     */
    public static String getSomeMonthBefore(int months) {
        return LocalDate.now().minusMonths(months).format(YEAR_MONTH_FORMATTER);
    }

    /**
     * 获取某月前的日期
     *
     * @param months
     * @return
     */
    public static String getSomeMonthBeforeYMD(int months) {
        return LocalDate.now().minusMonths(months).format(DATE_FORMATTER);
    }


    /**
     * 获取本周第一天开始时间 (星期一)
     */
    public static String getWeekFirstDayTime() {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime firstDay = date.with(DayOfWeek.MONDAY);
        return firstDay.format(START_DATETIME_FORMATTER);
    }

    /**
     * 获取本周最后一天结束时间 (星期天)
     */
    public static String getWeekLastDayTime() {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime lastDay = date.with(DayOfWeek.SUNDAY);
        return lastDay.format(END_DATETIME_FORMATTER);
    }

    /**
     * 获取本周第一天开始时间 (星期一)
     */
    public static String getPreviousWeekFirstDayTime() {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime firstDay = date.minus(1, ChronoUnit.WEEKS).with(DayOfWeek.MONDAY);
        return firstDay.format(START_DATETIME_FORMATTER);
    }

    /**
     * 获取本周最后一天结束时间 (星期天)
     */
    public static String getPreviousWeekLastDayTime() {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime lastDay = date.minus(1, ChronoUnit.WEEKS).with(DayOfWeek.SUNDAY);
        return lastDay.format(END_DATETIME_FORMATTER);
    }

    /**
     * 格式化日期为字符串 Date转String , yyyy-MM-dd HH:mm:ss
     *
     * @param date date
     * @return 日期字符串
     */
    public static String format(Date date) {
        Instant instant = date.toInstant();
        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
        return localDateTime.format(DATETIME_FORMATTER);
    }

    /**
     * 根据传入格式，格式化日期为字符串 Date转String
     *
     * @param date    date
     * @param pattern 格式
     * @return 日期字符串
     */
    public static String formatByPattern(Date date, String pattern) {
        Instant instant = date.toInstant();
        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
        return localDateTime.format(DateTimeFormatter.ofPattern(pattern));
    }

    /**
     * 解析字符串日期为Date String转Date
     *
     * @param dateStr 日期字符串
     * @param pattern 格式
     * @return Date
     */
    public static Date parse(String dateStr, String pattern) {
        LocalDateTime localDateTime = LocalDateTime.parse(dateStr, DateTimeFormatter.ofPattern(pattern));
        Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
        return Date.from(instant);
    }

    public static Date parse(String dateStr, DateTimeFormatter dateTimeFormatter) {
        LocalDateTime localDateTime = LocalDateTime.parse(dateStr, dateTimeFormatter);
        Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
        return Date.from(instant);
    }

    /**
     * 获取年
     */
    public static int getYear() {
        LocalTime localTime = LocalTime.now();
        return localTime.get(ChronoField.YEAR);
    }

    /**
     * 获取月份
     */
    public static int getMonth() {
        LocalTime localTime = LocalTime.now();
        return localTime.get(ChronoField.MONTH_OF_YEAR);
    }

    /**
     * 获取某月的第几天
     */
    public static int getMonthOfDay() {
        LocalTime localTime = LocalTime.now();
        return localTime.get(ChronoField.DAY_OF_MONTH);
    }

    /**
     * 返回当前的日期
     */
    public static LocalDate getCurrentLocalDate() {
        return LocalDate.now();
    }

    /**
     * 返回当前时间
     */
    public static LocalTime getCurrentLocalTime() {
        return LocalTime.now();
    }

    /**
     * 返回当前日期时间
     */
    public static LocalDateTime getCurrentLocalDateTime() {
        return LocalDateTime.now();
    }

    /**
     * yyyy-MM-dd
     */
    public static String getCurrentDateStr() {
        return LocalDate.now().format(DATE_FORMATTER);
    }

    /**
     * yyMMdd
     */
    public static String getCurrentShortDateStr() {
        return LocalDate.now().format(SHORT_DATE_FORMATTER);
    }

    /**
     * yyyy-MM
     */
    public static String getCurrentMonthStr() {
        return LocalDate.now().format(YEAR_MONTH_FORMATTER);
    }

    /**
     * yyyy-MM-dd HH:mm:ss
     */
    public static String getCurrentDateTimeStr() {
        return LocalDateTime.now().format(DATETIME_FORMATTER);
    }

    /**
     * yyyy-MM-dd HH:mm:ss SSS
     */
    public static String getCurrentLongDateTimeStr() {
        return LocalDateTime.now().format(LONG_DATETIME_FORMATTER);
    }

    /**
     * yyMMddHHmmss
     */
    public static String getCurrentShortDateTimeStr() {
        return LocalDateTime.now().format(SHORT_DATETIME_FORMATTER);
    }

    /**
     * HHmmss
     */
    public static String getCurrentTimeStr() {
        return LocalTime.now().format(TIME_FORMATTER);
    }

    public static String getCurrentDateStr(String pattern) {
        return LocalDate.now().format(DateTimeFormatter.ofPattern(pattern));
    }

    public static String getCurrentDateTimeStr(String pattern) {
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(pattern));
    }

    public static String getCurrentTimeStr(String pattern) {
        return LocalTime.now().format(DateTimeFormatter.ofPattern(pattern));
    }

    public static LocalDate parseLocalDate(String dateStr, String pattern) {
        return LocalDate.parse(dateStr, DateTimeFormatter.ofPattern(pattern));
    }

    public static LocalDateTime parseLocalDateTime(String dateTimeStr, String pattern) {
        return LocalDateTime.parse(dateTimeStr, DateTimeFormatter.ofPattern(pattern));
    }

    public static LocalTime parseLocalTime(String timeStr, String pattern) {
        return LocalTime.parse(timeStr, DateTimeFormatter.ofPattern(pattern));
    }

    public static String formatLocalDate(LocalDate date, String pattern) {
        return date.format(DateTimeFormatter.ofPattern(pattern));
    }

    public static String formatLocalDateTime(LocalDateTime datetime, String pattern) {
        return datetime.format(DateTimeFormatter.ofPattern(pattern));
    }

    public static String formatLocalTime(LocalTime time, String pattern) {
        return time.format(DateTimeFormatter.ofPattern(pattern));
    }

    public static LocalDate parseLocalDate(String dateStr) {
        return LocalDate.parse(dateStr, DATE_FORMATTER);
    }

    public static LocalDateTime parseLocalDateTime(String dateTimeStr) {
        return LocalDateTime.parse(dateTimeStr, DATETIME_FORMATTER);
    }

    public static LocalDateTime parseLongLocalDateTime(String longDateTimeStr) {
        return LocalDateTime.parse(longDateTimeStr, LONG_DATETIME_FORMATTER);
    }

    public static LocalTime parseLocalTime(String timeStr) {
        return LocalTime.parse(timeStr, TIME_FORMATTER);
    }

    public static String formatLocalDate(LocalDate date) {
        return date.format(DATE_FORMATTER);
    }

    public static String formatLocalDateTime(LocalDateTime datetime) {
        return datetime.format(TIME_FORMATTER);
    }

    public static String formatLocalTime(LocalTime time) {
        return time.format(TIME_FORMATTER);
    }

    /**
     * 日期相隔毫秒
     */
    public static long periodMilliseconds(LocalDateTime startDateTime, LocalDateTime endDateTime) {
        return Duration.between(startDateTime, endDateTime).get(ChronoUnit.MILLIS);
    }

    /**
     * 日期相隔秒
     */
    public static long periodSeconds(LocalDateTime startDateTime, LocalDateTime endDateTime) {
        return Duration.between(startDateTime, endDateTime).get(ChronoUnit.MILLIS.SECONDS);
    }

    /**
     * 日期相隔分钟
     */
    public static long periodMinutes(LocalDateTime startDateTime, LocalDateTime endDateTime) {
//        startDateTime = startDateTime.withNano(0);
//        endDateTime = endDateTime.withNano(0);
        return Duration.between(startDateTime, endDateTime).toMinutes();
    }


    /**
     * 日期相隔小时
     */
    public static long periodHours(LocalDateTime startDateTime, LocalDateTime endDateTime) {
        return Duration.between(startDateTime, endDateTime).get(ChronoUnit.HOURS);
    }

    /**
     * 日期相隔天数
     */
    public static long periodDays(LocalDate startDate, LocalDate endDate) {
        return startDate.until(endDate, ChronoUnit.DAYS);
    }

    public static long periodDays(LocalDateTime startDate, LocalDateTime endDate) {
        return startDate.until(endDate, ChronoUnit.DAYS);
    }

    /**
     * 日期相隔周数
     */
    public static long periodWeeks(LocalDate startDate, LocalDate endDate) {
        return startDate.until(endDate, ChronoUnit.WEEKS);
    }

    /**
     * 日期相隔月数
     */
    public static long periodMonths(LocalDate startDate, LocalDate endDate) {
        return startDate.until(endDate, ChronoUnit.MONTHS);
    }

    /**
     * 日期相隔年数
     */
    public static long periodYears(LocalDate startDate, LocalDate endDate) {
        return startDate.until(endDate, ChronoUnit.YEARS);
    }

    /**
     * 获取多少周之后的今天开始时间
     */
    public static String getSomeWeekToday(int num) {
        return LocalDate.now().plusWeeks(num).format(START_DATETIME_FORMATTER);
    }

    /**
     * 是否当天
     */
    public static boolean isToday(LocalDate date) {
        return getCurrentLocalDate().equals(date);
    }

    public static boolean isToday(Date date) {
        LocalDate localDateTime = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
        return getCurrentLocalDate().equals(localDateTime);
    }

    /**
     * 获取当前毫秒数
     */
    public static Long toEpochMilli(LocalDateTime dateTime) {
        return dateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
    }

    /**
     * 判断是否为闰年
     */
    public static boolean isLeapYear(LocalDate localDate) {
        return localDate.isLeapYear();
    }


    /**
     * LocalDateTime 转 Date
     */
    public static Date localDateTimeChangeDate(LocalDateTime localDateTime) {
        return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
    }


    /**
     * Date 转 LocalDateTime
     */
    public static LocalDateTime dateChangeLocalDateTime(Date date) {
        return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
    }

    public static String getSomeDayToday(Integer num) {
        return LocalDate.now().plusDays(num).format(START_DATETIME_FORMATTER);
    }


    /**
     * 多久以前
     * 传入以前的日期，与当前时间对比
     *
     * @param targetTime
     * @return
     */
    public static String getIntervalFormatting(Date targetTime) {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime target = targetTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();

        Period period = Period.between(target.toLocalDate(), now.toLocalDate());
        Duration duration = Duration.between(target, now);

        if (period.getYears() > 0) {
            return period.getYears() + "年前";
        } else if (period.getMonths() > 0) {
            return period.getMonths() + "个月前";
        } else if (period.getDays() > 0) {
            return period.getDays() + "天前";
        } else if (duration.toHours() > 0) {
            return duration.toHours() + "小时前";
        } else if (duration.toMinutes() > 0) {
            return duration.toMinutes() + "分钟前";
        } else {
            return "刚刚";
        }
    }

    public static Integer compareWithToday(Date targetTime) {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime target = targetTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();

        Period period = Period.between(now.toLocalDate(), target.toLocalDate());

        return period.getDays();
    }
}
